package test_achieve.h5;

import constant.Constant;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.util.concurrent.TimeUnit;

/**
 * Created by chenkuo on 2017/7/19.
 */
public class Login {
    @Given("^h进入用户登录界面$")
    public void h已经进入用户登录界面() throws Throwable {
//        System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
//        Constant.driverH = new FirefoxDriver();
        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
        String baseUrl = Constant.h5LoginURL;
        Constant.driverH = new ChromeDriver();
        Constant.driverH.manage().timeouts().implicitlyWait(Constant.hideWaitTime, TimeUnit.SECONDS);
        Constant.driverH.get(baseUrl);
    }

    @Given("^h选择密码登录$")
    public void h选择密码登录() throws Throwable {
        Constant.driverH.findElement(By.xpath("//*[@id=\"iss-app\"]/div/ul/li[2]")).click();
    }

    @Given("^h输入用户账户密码:(.+)：(.+)$")
    public void h输入用户账户密码(String name,String pw) throws Throwable {
        Constant.driverH.findElement(By.xpath("//*[@id=\"iss-app\"]/div/div[2]/div/input[1]")).sendKeys(name);
        Constant.driverH.findElement(By.xpath("//*[@id=\"iss-app\"]/div/div[2]/div/input[2]")).sendKeys(pw);
    }

    @Given("^h点击登录按钮$")
    public void h点击登录按钮() throws Throwable {
        Constant.driverH.findElement(By.xpath("//*[@id=\"iss-app\"]/div/div[2]/div/button")).click();
    }

    @Then("^h登录成功$")
    public void h登录成功() throws Throwable {
        //登录成功后进入下单页面
        Assert.assertTrue(Constant.driverH.findElement(
                By.cssSelector("div.addr-mess")).getText().equals("物品从哪里寄出"));
    }
    @Then("^h弹出快捷登录页面$")
    public void h弹出快捷登录页面() throws Throwable {
        Assert.assertTrue(Constant.driverH.findElement(
                By.cssSelector("p.pop-title")).getText().equals("快捷登录"));
    }

//    public static  void main(String  args[]){
//        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
//        WebDriver driver =new ChromeDriver();
//         final JavascriptExecutor js = (JavascriptExecutor) driver;
//        js.executeScript("window.open('','testwindow','width=400,height=200')");
//        driver.close();
//        driver.switchTo().window("testwindow");
//        js.executeScript("window.moveTo(0,0);");
//        js.executeScript("window.resizeTo(1400,1024);");
//        driver.get("http://m.ss.bingex.com/user/login.html");
//    }


}
